﻿using System;
using System.Runtime.Serialization;
using System.Xml.Linq;

namespace NCMIS.ObjectModel.MetaData
{
    /// <summary>
    /// Represents the folder object-type definition, which describes a folder object's types attribute values and property defintions.
    /// </summary>
    [DataContract(Name = "cmisTypeFolderDefinitionType", Namespace = CmisNs.Cmis)]
    public class TypeFolderDefinition : TypeDefinition
    {
        public override XElement ToXElement()
        {
            XNamespace ns = CmisNs.Cmis;
            XNamespace nsra = CmisNs.Cmisra;
            XNamespace nsw3 = CmisNs.W3instance;

            XElement typeElement = new XElement(nsra + "type", new XAttribute(nsra + "id", this.Id),
                new XAttribute(XNamespace.Xmlns + "xsi", CmisNs.W3instance),
                new XAttribute(nsw3 + "type", "cmis:cmisTypeFolderDefinitionType"),
                new XElement(ns + "id", this.Id),
                new XElement(ns + "localName", this.LocalName),
                new XElement(ns + "localNamespace", this.LocalNamespace),
                new XElement(ns + "displayName", this.DisplayName),
                new XElement(ns + "queryName", this.QueryName),
                new XElement(ns + "description", this.Description),
                new XElement(ns + "baseId", BaseIdToString(this.BaseId)),
                new XElement(ns + "creatable", this.Creatable),
                new XElement(ns + "fileable", this.Fileable),
                new XElement(ns + "queryable", this.Queryable),
                new XElement(ns + "fullTextIndexed", this.FulltextIndexed),
                new XElement(ns + "includedInSupertypeQuery", this.IncludedInSupertypeQuery),
                new XElement(ns + "controllablePolicy", this.ControllablePolicy),
                new XElement(ns + "controllableACL", this.ControllableAcl));
            if (this.PropertyDefinitions != null)
            {
                foreach (PropertyDefinition propertyDefinition in this.PropertyDefinitions)
                {
                    typeElement.Add(propertyDefinition.ToXElement());
                }
            }

            return typeElement;
        }
    }
}
